package com.zhentao.filter;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;

@Configuration
@CrossOrigin(origins = "*")
public class GatewayRoutes {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("dashboard_route", r -> r.path("/dashboard/**")
                        .uri("http://localhost:8001"))
                .route("mobile_route", r -> r.path("/mobile/**")
                        .uri("http://localhost:8001"))
                .route("param-category_route", r -> r.path("/param/category/**")
                        .uri("http://localhost:8001"))
                .route("param-metrics_route", r -> r.path("/param/metrics/**")
                        .uri("http://localhost:8001"))
                .route("param-recommendation_route", r -> r.path("/param/recommendation/**")
                        .uri("http://localhost:8001"))
                .route("param-rule_route", r -> r.path("/param/rule/**")
                        .uri("http://localhost:8001"))
                .route("customs-anomaly-detection", r -> r.path("/AnomalyQuery/**")
                        .uri("http://localhost:7002"))
                .route("customs-data-query", r -> r.path("/query/**")
                        .uri("http://localhost:7001"))
                .build();
    }
}
